<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/css/public.css" media="all">
    <style>
        .layui-form-item{
            margin-top: 10px;
            margin-right: 30px;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form layuimini-container">
    <div class="layui-form-item">
        <label class="layui-form-label ">昵称</label>
        <div class="layui-input-block">
            <input type="text" name="name" placeholder="请输入昵称" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">手机号</label>
        <div class="layui-input-block">
            <input type="text" name="phone" placeholder="请输入手机号" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label ">账号</label>
        <div class="layui-input-block">
            <input type="text" name="account" placeholder="请输入账号" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-block">
            <input type="text" name="password" placeholder="请输入密码" value="" class="layui-input">
        </div>
    </div>



    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>

<script src="/static/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['layer', 'form', 'laydate'], function () {
        var laydate = layui.laydate;
        var form = layui.form;
        var layer = layui.layer;
        var $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            $.ajax({
                type:'POST',
                url:'/admin/user_list/updateData',
                dataType:'json',
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                data:data.field,
                success:function(data){
                    console.log(data)
                    if(data.status == 1){
                        layer.alert(data.message,{icon:6},function(){
                            parent.location.reload(true);
                        });
                    }else{
                        layer.alert(data.message,{icon:5});
                    }
                },
                error:function(){
                    //错误信息
                }

            });
            return false;
        });


        //全选被选中  其他都被勾选
        form.on('checkbox(checkall)', function (data) {
             var id = data.value;
            // console.log(id)
            //这里实现勾选
            var checkone = '.'+'checkone'+id
            $(checkone).each(function (index, item) {
                item.checked = data.elem.checked;
            });
            form.render('checkbox');
        });
        //有一个未选中全选取消选中
        // form.on('checkbox(c_one)', function (data) {
        //     var item = $('.c_one');
        //     console.log(item)
        //     for (var i = 0; i < item.length; i++) {
        //         if (item[i].checked == false) {
        //             $("#c_all").prop("checked", false);
        //             form.render('checkbox');
        //             break;
        //         }
        //     }
        //     //如果都勾选了  勾上全选
        //     var all = item.length;
        //     for (var i = 0; i < item.length; i++) {
        //         if (item[i].checked == true) {
        //             all--;
        //         }
        //     }
        //     if (all == 0) {
        //         $("#c_all").prop("checked", true);
        //         form.render('checkbox');
        //     }
        // });
        //取值
        form.on('checkbox', function (data) {
            var myaaa = document.getElementsByName("center_permit[]")
            var s = '';
            if (data.value == 0 && $("#c_all").is(":checked")) {
                s = 0 + ',';
            } else if ($("#c_all").is(":checked")) {
                s = 0 + ',';
            } else {
                for (var i = 0; i < myaaa.length; i++) {
                    if (myaaa[i].checked) s += myaaa[i].value + ',';
                }
            }
            $("#doorNum").attr("value", s.slice(0, s.length - 1))

        });


    });
</script>
</body>
</html>